<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    //用户注册页面
    public function index()
    {
        return view('admin.login.index');
    }

    //用户登录页面
    public function login()
    {
        $this->validate(request(), [
            'name'  => 'required|min:2',
            'password'  =>'required|min:6',
        ]);

        $user = request(['name', 'password']);
        if (\Auth::guard('admin')->attempt($user)) {
            return redirect('/admin/home');
        }

        return \Redirect::back()->withErrors('用户名和密码不匹配');
    }

    //登出
    public function logout()
    {
        \Auth::guard('admin')->logout();

        return redirect('/admin/login');
    }
}
